package com.xls.future.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;

import com.xls.future.utils.LogUtil;

/**
 * Created by Administrator on 2017/10/13.
 */

public class BaseFragment extends Fragment {

    protected boolean isFirstVisible = false;

    public BaseFragment() {
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        isFirstVisible = true;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        isFirstVisible = false;
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    /**
     * 设置ActionBar的可见性
     * @param visible
     */
    public void setSupportActionBarVisibility(boolean visible){
        Activity activity = getActivity();
        ActionBar actionBar = null;
        if(activity instanceof AppCompatActivity){
            actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        }

        if(actionBar!=null){
            if(actionBar.isShowing()!=visible){
                if(visible){
                    actionBar.show();
                    LogUtil.d("xiong","set actionBar show");
                }else{
                    actionBar.hide();
                    LogUtil.d("xiong","set actionBar hide");
                }
            }

            LogUtil.d("xiong","actionBar isShowing = "+actionBar.isShowing());
        }
    }
}
